package tcln.sors.model.product.dom;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

import tcln.sors.model.base.dom.AbstractSorsNamedEntity;

/**
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
@Entity
@Table(name = "TBL_PROD_SPEC_PROP")
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "PROD_SPEC_PROP_ID")) })
public class ProductSpecProperty extends AbstractSorsNamedEntity {
    private static final long serialVersionUID = 1L;

    /**
     * JSON string representing property value.
     */
    private String value;

    /**
     * Data type (i.e. full classname).
     */
    private String dataType;

    /**
     * Owner product specification.
     */
    private ProductSpecification productSpecification;

    /**
     * Returns current value of {@link #value}.
     * 
     * @return the {@link #value}.
     */
    @NotNull
    @Length(max = 500)
    @Column(name = "PROP_VALUE", length = 500)
    public String getValue() {
        return value;
    }

    /**
     * Sets new value for {@link #value}.
     * 
     * @param value
     *            the new value to set
     */
    public void setValue(String value) {
        this.value = value;
    }

    /**
     * Returns current value of {@link #dataType}.
     * 
     * @return the {@link #dataType}.
     */
    @Length(max = 100)
    @Column(name = "PROP_DATA_TYPE")
    public String getDataType() {
        return dataType;
    }

    /**
     * Sets new value for {@link #dataType}.
     * 
     * @param dataType
     *            the new dataType to set
     */
    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    /**
     * Returns current value of {@link #productSpecification}.
     * 
     * @return the {@link #productSpecification}.
     */
    @ManyToOne(cascade = { CascadeType.ALL })
    @JoinColumn(name = "PRODUCT_SPEC_ID")
    public ProductSpecification getProductSpecification() {
        return productSpecification;
    }

    /**
     * Sets new value for {@link #productSpecification}.
     * 
     * @param productSpecification
     *            the new productSpecification to set
     */
    public void setProductSpecification(ProductSpecification productSpecification) {
        this.productSpecification = productSpecification;
    }
}
